unit U_S_Vendas;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids, Wwdbigrd, Wwdbgrid, DB, Wwdatsrc, Buttons;

type
  TS_Vendas = class(TForm)
    BVendas: TBitBtn;
    Dsq_vendas: TwwDataSource;
    Grid_Vendas: TwwDBGrid;
    E_Cliente: TEdit;
    BQuadro: TBitBtn;
    wwDBGrid1: TwwDBGrid;
    Dsq_Obs: TwwDataSource;
    procedure BVendasClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure BQuadroClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  S_Vendas: TS_Vendas;

implementation

uses U_Dm_Querys, uFunRede;

{$R *.dfm}

procedure TS_Vendas.BVendasClick(Sender: TObject);
begin
  Dm_Querys.Qry_Clientes.Close;
  Dm_Querys.Qry_Clientes.SQL.Clear;
  Dm_Querys.Qry_Clientes.SQL.Add('select * from CLIENTES ');
  Dm_Querys.Qry_Clientes.SQL.Add('WHERE EXISTS (SELECT COD_CLIENTE FROM MV_MOVIMENTO WHERE (MV_MOVIMENTO.COD_CLIENTE = CLIENTES.CODIGO) and (CLIENTES.NOME_CLIENTE like :pNome) )');
  Dm_Querys.Qry_Clientes.ParamByName('pNome').AsString:='%'+trim(E_Cliente.Text)+'%';
  Dm_Querys.Qry_Clientes.SQL.Add('ORDER by NOME_CLIENTE');
  Dm_Querys.Qry_Clientes.Open;
end;

procedure TS_Vendas.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action:=caFree;
  S_Vendas:=nil;
end;

procedure TS_Vendas.BQuadroClick(Sender: TObject);
begin
  Dm_Querys.Qry_Clientes_Obs.Close;
  Dm_Querys.Qry_Clientes_Obs.SQL.Clear;
  Dm_Querys.Qry_Clientes_Obs.SQL.Add('select * from CLIENTES_OBS ');
  Dm_Querys.Qry_Clientes_Obs.SQL.Add(' WHERE (OBS like :pQuadro) ');
  Dm_Querys.Qry_Clientes_Obs.ParamByName('pQuadro').AsString:='%'+trim(E_Cliente.Text)+'%';
  Dm_Querys.Qry_Clientes_Obs.Open;
end;

procedure TS_Vendas.FormShow(Sender: TObject);
begin
  Dm_Querys.Qry_Clientes_Obs.Close;
  Dm_Querys.Qry_Clientes_Obs.SQL.Clear;
  Dm_Querys.Qry_Clientes.Close;
  Dm_Querys.Qry_Clientes.SQL.Clear;
end;

end.
